<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRechargeTable extends Migration {
	public function up() {
		//充值
		Schema::create( 'recharge', function ( Blueprint $table ) {
			$table->increments( 'id' );
			$table->unsignedInteger( 'user_id' )->comment( '用户ID' );
			$table->string( 'out_trade_no', 23 )->comment( '订单号' );
			$table->string( 'subject' )->comment( '标题' );
			$table->unsignedDecimal( 'recharge_amount', 10, 2 )->comment( '充值金额' );
			$table->unsignedDecimal( 'total_amount', 10, 2 )->default( 0 )->comment( '实收金额' );
			$table->boolean( 'pay_status' )->default( false )->comment( '支付状态 未支付:0 已支付:1' );
			$table->boolean( 'refund_status' )->default( false )->comment( '退款状态 未退款:0 退款:1' );
			$table->boolean( 'deleted' )->default( false )->comment( '管理员删除 0=未删除,1=删除' );
			$table->timestamps();
		} );
		//退款日志
		Schema::create( 'refund_log', function ( Blueprint $table ) {
			$table->increments( 'id' );
			$table->unsignedInteger( 'user_id' )->comment( '用户ID' );
			$table->string( 'out_trade_no', 23 )->comment( '订单号' );
			$table->string( 'trade_no', 64 )->comment( '第三方交易号' );
			$table->string( 'buyer_id', 64 )->comment( '第三方用户ID' );
			$table->unsignedTinyInteger( 'type' )->comment( '退款类型 支付宝:1 微信:2' );
			$table->decimal( 'total_amount', 10, 2 )->comment( '退款金额' );
			$table->timestamp( 'refund_time' )->comment( '退款时间' );
			$table->timestamps();
		} );
	}

	public function down() {
		Schema::dropIfExists( 'recharge' );
		Schema::dropIfExists( 'refund_log' );
	}
}
